package com.hunan.api.catv.mq.consumer;

import com.hunan.api.catv.common.Constants;
import com.hunan.api.catv.mq.MqConstants;
import com.hunan.api.catv.service.biz.toupiao.TouPiaoBiz;
import com.hunan.api.catv.utils.RedisUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LoginAddLotteryCosumer {

    private static final Integer ADD_TICKETS_EACH_FIVE_INVITE_TYPE = 1;
    private static final String LOGIN_ADD_LOTTERY_ACTIVITY_ID = "10030";
    public static final Logger log = LoggerFactory.getLogger(LoginAddLotteryCosumer.class);

    @Autowired
    TouPiaoBiz touPiaoBiz;

    @Autowired
    RedisUtils redisUtils;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = MqConstants.LOGIN_ADD_LOTTERY_QUEUE, durable = "true"), exchange = @Exchange(value = MqConstants.LOGIN_ADD_LOTTERY_EXCHANGE, durable = "true", type = "topic"), key = MqConstants.LOGIN_ADD_LOTTERY_ROUTINGKEY))
    public void tasks(Integer msg) {
        log.info("[登录签到增加抽奖收到任务消息:{}]", msg);

        Integer memberId = msg;
        try {
            touPiaoBiz.addLottery(memberId, ADD_TICKETS_EACH_FIVE_INVITE_TYPE, Constants.toupiao_conf, LOGIN_ADD_LOTTERY_ACTIVITY_ID);
        } catch (Exception e) {
            log.error("[登录签到增加抽奖失败:]", e);
        }
    }
}
